﻿using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using 纸片人.InterfaceFolder;
using 纸片人.Shaders;

namespace 纸片人.win2dEffectControl.DataClass
{
    public class SwellOrExtrusionEffectData : PixelShaderEffectData
    {
        private float radius=0.5f;
        private float amount=0f;
        private Vector2 position=new Vector2(0.5f,0.5f);

        public float Radius { get => radius; set { radius = value; OnPropertyChanged(); SetIsChanges(); } }
        public float Amount { get => amount; set { amount = value; OnPropertyChanged(); SetIsChanges(); } }
        public Vector2 Position { get => position; set { position = value; OnPropertyChanged(); SetIsChanges(); } }


        public override ShaderType shaderShaderPath { get; } = ShaderType.SwellOrExtrusion;

        public override ICanvasImage GetEffect(CanvasDevice device, bool compression)
        {
            var source = GetSourceEffect(device, compression);
            if (source == null)
                return null;
            if (shaderCodeBytes == null)
                return null;

            var effect = new PixelShaderEffect(shaderCodeBytes);
            effect.Source1 = source;
            var sqrt = (float)(Math.Sqrt(Math.Pow(Size.Width / 2, 2) + Math.Pow(Size.Height / 2, 2)));
            var r = sqrt * Radius;

            effect.SetFloat("amount", Amount);
            effect.SetFloat("radius", r);
            effect.SetFloat2("position", new Vector2((float)(Position.X * Size.Width), (float)(Position.Y * Size.Height)));
            effect.SetFloat2("size", new System.Numerics.Vector2((float)Size.Width, (float)Size.Height));
            return effect;
        }
    }
}
